package utils;

import java.util.*;

public class DataUtils {
    private static Map<String, List<String>> dictionary=new HashMap<>(16);
    static {
        List<String> common=Arrays.asList("keys","expire","del");
        List<String> string=Arrays.asList("get","set");
        List<String> hash=Arrays.asList("hset","hget","hdel","hgetall");
        List<String> set=Arrays.asList("sadd","smembers","sismember","srem");
        List<String> zset=Arrays.asList("zadd","zrange","zrank","zrem");
        List<String> list=Arrays.asList("lpush","rpush","lrange","lrem");
        dictionary.put("common",common);
        dictionary.put("string",string);
        dictionary.put("hash",hash);
        dictionary.put("set",set);
        dictionary.put("zset",zset);
        dictionary.put("list",list);
    }
    public static String getData(String arg){
        String[] commands = arg.split("\\s+");
        //标记位
        String flag=null;
        String command = commands[0];
        //数据源封装
        for (Map.Entry<String, List<String>> entry : dictionary.entrySet()) {
            String k = entry.getKey();
            List<String> instructions = entry.getValue();
            boolean f = false;
            for (String instruction : instructions) {
                if (command.equals(instruction)) {
                    f=true;
                    flag=k;
                    break;
                }
            }
            if (f) break;
        }
        return flag+" "+arg;
    }

}

